package com.atguigu.jsp.servlet;

import com.atguigu.jsp.entity.Soldier;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/Servlet04TestJSTL")
public class Servlet04TestJSTL extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 1、创建一个集合并存入数据
        List<Soldier> list = List.of(
                new Soldier(1, "张飞",  "男", 18),
                new Soldier(2, "关羽",  "男", 19),
                new Soldier(3, "赵云",  "男", 20),
                new Soldier(4, "黄忠",  "男", 21),
                new Soldier(5, "马超",  "男", 22),
                new Soldier(6, "魏延",  "男", 23),
                new Soldier(7, "许褚",  "男", 24)
        );

        // 2、把集合存入 request 域中
        request.setAttribute("list", list);

        // 3、转发请求
        request.getRequestDispatcher("/pages/target.jsp").forward(request, response);
    }
}
